from typing_extensions import Self
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.ui import Console
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_core.models import UserMessage
from autogen_agentchat.messages import BaseAgentEvent, BaseChatMessage, MultiModalMessage, StopMessage, TextMessage, ToolCallExecutionEvent
from autogen_core import Component, Image as AGImage
from autogen_agentchat.base import TaskResult, TerminatedException, TerminationCondition
from autogen_agentchat.conditions import ExternalTermination, MaxMessageTermination, TextMentionTermination
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_core import CancellationToken
import PIL
from autogen_core import Image
from io import BytesIO
import asyncio
import requests
from typing import Literal, Sequence
from pydantic import BaseModel


# Define a model client. You can use other model client that implements
# the `ChatCompletionClient` interface.


model_client = OpenAIChatCompletionClient(
    model="qwen-plus",  # Using qwen-plus instead of qwen-vl-max for better function calling support
    api_key="sk-925b8bbb82424b74a8de940d2dc5a6ce",
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
    model_info={
        "vision": False,
        "function_calling": True,
        "json_output": False,
        "family": "unknown",
        "structured_output": True,
        "max_tokens": 8192,
        "top_p": 0.8
    }
)


primary_agent = AssistantAgent(
    name="primary",
    model_client=model_client,
    model_client_stream=False,
    system_message="You are a helpful assistant."
)

async def main():
    result = await primary_agent.on_messages([TextMessage(content="Hello, how are you?", source="user")], CancellationToken())
    print(result)
    await model_client.close()
    agent_state = await primary_agent.save_state()
    print("\n\n agent_state:\n")
    print(agent_state)


asyncio.run(main())